/*
 * @Descripttion: $0
 * @version: 
 * @Author: linPing
 * @Date: 2019-10-29 01:26:12
 * @LastEditTime: 2019-11-04 16:46:47
 */
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */
import {NavigationActions} from 'react-navigation'
import {createBottomTabNavigator} from 'react-navigation-tabs'
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'
import FontAwesome from 'react-native-vector-icons/FontAwesome'
import {BackHandler} from 'react-native'  
import React, {Fragment} from 'react';
import NavigationUtil from '../navigator/NavigationUtil'
import DynamicTabNavigator from '../navigator/DynamicTabNavigator'
import {bindBackExitApp,removeBackExitApp} from '../component/androidBack'
import SafeAreaViewPlus from "../common/SafeAreaViewPlus";
import {observer, inject} from 'mobx-react';
import {
  StyleSheet,
  View,
  Text,
} from 'react-native';




@inject('appStore')
@observer
export default class IndexPage extends React.Component{
  constructor(props){
    super(props)
    console.disableYellowBox = true
    this.themeColor=this.props.appStore.theme
  }

  

  componentDidMount(){
    bindBackExitApp()

    BackHandler.addEventListener('hardwareBackPress',this.onBackPress)
   
  }

  componentWillUnmount(){
    removeBackExitApp()
    BackHandler.removeEventListener('hardwareBackPress',this.onBackPress)
  }

  /**
   * 物理 Android 中的物理返回键
   * @returns {boolean}
   * **/

   onBackPress =()=>{
     
     const {dispatch,navigation} =this.props

     if(global.routerName==="IndexPage"){
       return false
     }else{
      // NavigationUtil.goBack(this.props.navigation)
      navigation.dispatch(NavigationActions.back())
      return true
     }
    
   }
 
  render(){
    console.log(this.props)
    NavigationUtil.navigation = this.props.navigation
    return (
      <SafeAreaViewPlus
             topColor={this.themeColor}
        >
            <DynamicTabNavigator/>
        </SafeAreaViewPlus>
 
    )
  }
 
};

const styles = StyleSheet.create({

  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
    color:'#333',
  },
 
});


// const mapStateToProps = state => ({
//   nav:state.nav,
//   theme:state.theme
// })
// export default connect(mapStateToProps)(HomePage)